package puzzle.projecteuler.p200;

import java.math.BigInteger;

import astudy.util.AdvMath;

public class Problem132C {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		long s = System.currentTimeMillis();		
		long n = 1000000000;
		long p = 7;	//p != 2,3,5
		long sum = 0;
		int count = 40;
		while (count > 0) {
			if (AdvMath.isPrime(p)) {
				long d = AdvMath.gcd(p-1, n);
				BigInteger r = BigInteger.TEN.modPow(BigInteger.valueOf(d), BigInteger.valueOf(p));
				if (r.compareTo(BigInteger.ONE) == 0) {
					count --;
					sum += p;
				}
			}
			p ++;
		}
		System.out.println("sum = " + sum);
		System.out.println((System.currentTimeMillis() - s) + " ms");

	}
}
